package com.yd.cfckc.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @author cuiyufeng
 * @email cuiyufeng1458@yundasys.com
 * @date 2020/10/16 2:21 下午
 */
public class RedisPool {


    public static JedisPool pool = null;

    // TODO: 默认端口配置情况，发布前需要根据情况修改
    public static String defhost = "127.0.0.1";
    public static int defPort = 6379; // 非分布式服务，默认1个,查询系统值为 9600，仲裁系统和巴枪系统为9400

    public static void initPool(){
        JedisPoolConfig config = new JedisPoolConfig();
        pool = new JedisPool(config, defhost, defPort);
        System.out.println("====Init OK! (RedisPool.pool)");
    }

    public static JedisPool getPool() {
        if (pool == null) {
            initPool();
        }
        return pool;
    }

    public static void returnResource(JedisPool pool, Jedis redis) {
        if (redis != null) {
            pool.returnResource(redis);
        }
    }
}
